﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-05-21-20:06
//  * @Description:
//  */

using Code.GameLogic.BaseClass;
using UnityEngine;

namespace Code.GameLogic.GameCamera
{
    public class CameraController : AbsGameLogicController<CameraController,CameraController>
    {
        public float moveSpeed = 5.0f;

        public float zoomSpeed = 2.0f;

        public float minSize = 1.0f;
        public float maxSize = 3.0f;


        private void Start()
        {
        }

        void Update()
        {
            MoveCamera();
            ScaleCamera();
        }


        public void LockAtGo(GameObject targetGo)
        {
            PrintLogger("移动相机"+targetGo.transform);
            var position = targetGo.transform.position;
            transform.position = new Vector3(position.x,position.y,-10); // 将摄像机位置设置为目标位置，保持不变
            transform.LookAt(targetGo.transform);
        }


        private void MoveCamera()
        {
            float horizontalInput = Input.GetAxis("Horizontal");
            float verticalInput = Input.GetAxis("Vertical");

            Vector3 moveDirection = new Vector3(horizontalInput, verticalInput, 0).normalized;
            transform.Translate(moveDirection * moveSpeed * Time.deltaTime);
        }


        private void ScaleCamera()
        {
            float scrollInput = Input.GetAxis("Mouse ScrollWheel");
            float newSize = Camera.main.orthographicSize - scrollInput * zoomSpeed;
            Camera.main.orthographicSize = Mathf.Clamp(newSize, minSize, maxSize);
        }

        public override void InitGo(CameraController bo)
        {
            throw new System.NotImplementedException();
        }
    }
}